/* Copyright (c) 2021 Qualcomm Technologies International, Ltd. */
/* %%version */

#ifndef GATT_CAS_SERVER_COMMON_H
#define GATT_CAS_SERVER_COMMON_H

#include "gatt_cas_server_private.h"

#include "csr_bt_gatt_lib.h"
#include "csr_pmem.h"

#define GATT_CAS_SERVER_CCC_NOTIFY            (0x01)
#define GATT_CAS_SERVER_CCC_INDICATE          (0x02)

/* Required octets for the Client Configuration Characteristic */
#define GATT_CAS_SERVER_CCC_VALUE_SIZE        (2)



/**************************************************************************
NAME
    casServerSendAccessRsp

DESCRIPTION
    Send an access response to the GATT Manager library.
*/
void casServerSendAccessRsp(
        CsrBtGattId task,
        uint16 cid,
        uint16 handle,
        uint16 result,
        uint16 size_value,
        uint8 *const value
        );

/**************************************************************************
NAME
    casServerSendAccessErrorRsp

DESCRIPTION
    Send an access response to the GATT Manager library with an error status.
*/

#define casServerSendAccessErrorRsp(task, cid, handle, error) \
    casServerSendAccessRsp( \
            task, \
            cid, \
            handle, \
            error, \
            0, \
            NULL \
            )

/**************************************************************************
NAME
    casServerWriteGenericResponse

DESCRIPTION
    Send a generic response to the client after a writing.
*/
void casServerWriteGenericResponse(
        CsrBtGattId        task,
        uint16      cid,
        uint16      result,
        uint16      handle
        );

/***************************************************************************
NAME
    casServerSendCharacteristicChangedNotification

DESCRIPTION
    Send a notification to the client to notify that the value of
    a characteristic is changed.
*/
void casServerSendCharacteristicChangedNotification(
        CsrBtGattId  task,
        connection_id_t cid,
        uint16 handle,
        uint16 size_value,
        uint8 *const value
        );

/***************************************************************************
NAME
    casServerHandleReadClientConfigAccess

DESCRIPTION
    Deals with access of the CLIENT_CONFIG handles in case of reading.
*/
void casServerHandleReadClientConfigAccess(
        CsrBtGattId task,
        uint16 cid,
        uint16 handle,
        const uint16 client_config
        );

/***************************************************************************
NAME
    casServerHandleWriteClientConfigAccess

DESCRIPTION
    Deals with the access of a client config handle to be written and indicated
    to the application.
*/

void casServerHandleWriteClientConfigAccess(
        GCAS *common_audio_server,
        const GATT_MANAGER_SERVER_ACCESS_IND_T *access_ind);

/***************************************************************************
NAME
    casServerGetCidIndex

DESCRIPTION
    Search for a connected client by its cid and return its index in the array.
    If the client is not found, GATT_CAS_SERVER_INVALID_CID_INDEX is returned.
*/
uint8 casServerGetCidIndex(GCAS *common_audio_server, connection_id_t cid);

#endif /* GATT_CAS_SERVER_COMMON_H */
